#ifndef LOGINWINDOW_H
#define LOGINWINDOW_H

#include <QWidget>
#include <QMainWindow>
#include <QPushButton>
#include <QBoxLayout>
#include <QRadioButton>
#include <QSqlQuery>
#include <QSql>
#include <QSqlDatabase>
#include <QLineEdit>
#include <QAction>
#include <QIcon>
#include <QMouseEvent>
#include <QCheckBox>
#include <QMessageBox>
#include <QSettings>
#include <QTextStream>
#include <enrollwindow.h>

namespace Ui {
class LoginWindow;
}

class LoginWindow : public QWidget
{
    Q_OBJECT

public:
    explicit LoginWindow(QWidget *parent = 0);

    ~LoginWindow();


    void initLoginWindow();
    void connectDB();   //连接数据库

    bool mousePressed = false;
    QPoint mousePoint;
    void mousePressEvent(QMouseEvent *event)override;
    void mouseMoveEvent(QMouseEvent *event)override;
    void mouseReleaseEvent(QMouseEvent *event)override;




private slots:
    void on_remembercheckBox_clicked();

    void on_loginpushButton_clicked();

    void on_enrollpushButton_clicked();

    void on_closepushButton_clicked();
    void togglePasswordVisibility();

    void on_usernamelineEdit_textChanged(const QString &text);

    void on_maxpushButton_clicked();

private:
    Ui::LoginWindow *ui;
    QSqlDatabase db;


    QAction *displayPasswordAction;  // 切换密码显示/隐藏的 QAction
    QIcon eyeOpenIcon;  // 显示密码的图标
    QIcon eyecloseIcon;

    bool m_bVisible;


    QMap<QString,QString>savedPasswords;  // 保存用户名和密码

    QStringList m_passwdList;//保存密码
    QStringList m_isremberList;
    QStringList m_userNameList;
    QString isrembered;//是否记住密码
    QString username;
    QString password;



    void savePassword(const QString &username, const QString &password);
    void loadPasswords();

    void loadLastLoginInfo();  // 加载上次登录信息

};

#endif // LOGINWINDOW_H
